package com.core.life.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.core.common.pageModel.EasyuiDataGridJson;
import com.core.life.service.IConsumeCountService;
import com.core.life.vo.ConsumeCountVo;

@Controller
@RequestMapping("admin/consumeCount")
public class ConsumeCountController {

    @Resource
    private IConsumeCountService consumeCountService;

    /**
     * 跳转到消费消费统计
     */
    @RequestMapping("/index")
    public String everyConsumeIndex() {
        return "admin/countConsume/index";
    }

    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    @ResponseBody
    public EasyuiDataGridJson getList(HttpServletRequest request) {
        EasyuiDataGridJson json = new EasyuiDataGridJson();
        String strDate = request.getParameter("countDatetime");
        String consumeUserIds = request.getParameter("consumeUserIds");
        List<ConsumeCountVo> list = consumeCountService.getConsumeCountList(strDate, consumeUserIds);
        if (CollectionUtils.isNotEmpty(list)) {
            json.setTotal((long) list.size());
            json.setRows(list);
        }
        if (null == json.getRows()) {
            json.setTotal(0l);
            json.setRows(new ArrayList<ConsumeCountVo>());
        }

        return json;
    }
}
